import unittest as UT
from TCGs.Cards import *
##from TCGs.Cards import Vancard
##from TCGs.Cards import STACK

class TestVancard(UT.TestCase):
    
    def setUp(self):
        self.intSetterTdata = ('rarity', 'number')
        self.oneKSetterTdata = ('attack', 'shield')
        self.strSetterTdata = ('name', 'clan', 'race')
        self.enumSetterTdata = {'grade': (0, 1, 2, 3), \
                                 'type': ('b', 'g', 'd'), \
                                 'status': ('f', 't', 'r')}
##        self.dictSetterTdata = {'trigger': {'kind': ('critical', \
##                                                      'draw', \
##                                                      'heal', \
##                                                      'stand'), \
##                                             'valu': 5000}, \
##                                'ability': {'type': ('auto', \
##                                                      'act', \
##                                                      'cont'),
##                                            'cost': (('counterblast', \
##                                                      'soulblast', \
##                                                      'discard', \
##                                                      'personablast'), \
##                                                      'int'), \
##                                            'cond': ('int', \
##                                                     ('inDamage', \
##                                                      'inRearguard', \
##                                                      'inHand', \
##                                                      'inSoul',
##                                                      'ofType',
##                                                      'ofClan')), \
##                                            'desc': ((0, 1000, 2000, \
##                                                      3000, 4000, 5000), \
##                                                     ('boost', 'guard', 'draw',
##                                                      ''))}}
##        self.specSetterTdata = {'image': (), 'position': ()}
        self.vc = Vancard()

        
    def test_intSetters(self):
        for item in self.intSetterTdata:
            exec('self.vc.' + item + ' = "5"')
            self.assertEqual(eval("eval('self.vc.'+item)"), -1)
            exec('self.vc.' + item + ' = 5')
            self.assertEqual(eval("eval('self.vc.'+item)"), 5)

    def test_oneKSetters(self):
        for item in self.oneKSetterTdata:
            exec('self.vc.' + item + ' = "1000"')
            self.assertEqual(eval("eval('self.vc.'+item)"), -1)
            exec('self.vc.' + item + ' = 5')
            self.assertEqual(eval("eval('self.vc.'+item)"), -1)
            exec('self.vc.' + item + ' = 1000.0')
            self.assertEqual(eval("eval('self.vc.'+item)"), -1)
            exec('self.vc.' + item + ' = 0')
            self.assertEqual(eval("eval('self.vc.'+item)"), 0)
            exec('self.vc.' + item + ' = 10000')
            self.assertEqual(eval("eval('self.vc.'+item)"), 10000)

    def test_strSetters(self):
        for item in self.strSetterTdata:
            exec('self.vc.' + item + ' = 5')
            self.assertIn('Sorry', eval("eval('self.vc.'+item)"))
            exec('self.vc.' + item + ' = "5"')
            self.assertEqual(eval("eval('self.vc.'+item)"), "5")
            
    def test_enumSetters(self):
        for key, tpl in self.enumSetterTdata.items():
            for item in tpl:
                if type(item)==int:
                    exec('self.vc.' + key + ' = "' + str(item) + '"')
                    self.assertEqual(eval("eval('self.vc.'+key)"), -1)
                    exec('self.vc.' + key + ' = ' + str(item))
                    self.assertEqual(eval("eval('self.vc.'+key)"), item)
                elif type(item)==str:
                    exec('self.vc.' + key + ' = "' + item.upper() + '"')
                    self.assertEqual(eval("eval('self.vc.'+key)"), -1)
                    exec('self.vc.' + key + ' = "' + item + '"')
                    self.assertEqual(eval("eval('self.vc.'+key)"), item)
##                elif key=='dictType':
##                    print('self.vc.' + item + ' = 5')
##                elif key=='specType':
##                    print('self.vc.' + item + ' = 5')
        
##    def tearDown(self):
##        del self.Card
        

class TestSTACKs(UT.TestCase):
    
    def setUp(self):
        self.Stack = STACK()
        self.Deck = Deck()
        self.Hand = Hand()
        self.Drop = Drop()
        self.Xile = Xile()
        self.Field = Field()
        self.fore = foreField()
        self.main = mainField()
        self.rear = rearField()
        
    def test_STACK(self):
      # Generic STACK tests
        self.Stack.Type = 1
        self.assertEqual(self.Stack.Type, -1)
        self.Stack.Type = 'Deck'
        self.assertEqual(self.Stack.Type, 'Deck')
        self.Stack.List = 1
        self.assertEqual(self.Stack.List, [])
        self.Stack.List = []
        self.assertEqual(self.Stack.List, [])
        self.Stack.List = [1]
        self.assertIn('Sorry', self.Stack.List)
        self.Stack.List = [Vancard()]
        self.assert_(isinstance(self.Stack.List[0], CARD))
        self.assertEqual(self.Stack.count, 1)
      # Specific STACK type tests
        self.assertEqual(self.Deck.Type, 'Deck')
        self.assertEqual(self.Hand.Type, 'Hand')
        self.assertEqual(self.Drop.Type, 'Drop')
        self.assertEqual(self.Xile.Type, 'Xile')
        self.assertEqual(self.Field.Type, 'Field')
        self.assertEqual(self.fore.Type, 'fore')
        self.assertEqual(self.main.Type, 'main')
        self.assertEqual(self.rear.Type, 'rear')


if __name__ == '__main__':
    UT.main()